<?php
class Karyawan_model extends MY_Model {
	
    function Karyawan_model(){
        parent::MY_Model();
        $this->load->database();
        $this->table_name = "karyawan";
    }
    
    /**
     * 
     * @param $search_key
     * @param $where
     * @param $limit
     * @param $offset
     * @param $orderby
     */
    function select_last_entry($search_key=false, $where=false, $limit=10, $offset=0, $orderby=""){
    	$sql = $sqlo = $sqlw = "";
    	
    	$sqlw = "";
    	if ($search_key){
    		$sqlw .= ($sqlw? " AND " : ""). 
    			"(kary_id LIKE '%$search_key%' OR 
    			 kary_nama LIKE '%$search_key%' OR
    			 kary_tempat_lahir LIKE '%$search_key%' OR
    			 kary_tgl_lahir LIKE '%$search_key%' OR
    			 kary_jenis_kelamin LIKE '%$search_key%' OR
    			 kary_golongan_darah LIKE '%$search_key%' OR
    			 kary_status_marital LIKE '%$search_key%' OR
    			 kary_agama LIKE '%$search_key%' OR
    			 kary_email LIKE '%$search_key%' OR
    			 kary_tgl_masuk LIKE '%$search_key%' OR
    			 kary_tgl_keluar LIKE '%$search_key%' OR
    			 kary_sts_id LIKE '%$search_key%')";    		
    	}
    	if ($where){
    		$sqlw .= ($sqlw? " AND " : "").$where;
    	}
    	
    	$sqlw = $sqlw? " WHERE $sqlw " : "";
    	
    	if ($orderby){
    		$sqlo = "ORDER BY $orderby";
    	}
    	
    	$limit = " LIMIT $offset,$limit ";
    	return $query = $this->db->query(
    		"SELECT * FROM ".$this->table_name." $sqlw $sqlo $limit");
    }
        
    /**
     * 
     * @param $id
     */
    function select_by_id($id){
    	return $query = $this->db->get_where($this->table_name, array('kary_id' => $id));
    }
}